<template>
  <div class="index">
  	<!--<div class="sreePublic">
  		<div id="" style="text-align: center;">
  			<em class="iconfont" @click="vfun_back">&#xe61f;</em>
  		</div>
		收货地址
  	</div>-->
  	<div>
  		<div class="delivery">
  			<Radio-group v-model="vertical" vertical>
	  			<ul>
	  				<li v-for="(item,index) in MemberDeliverySet.list">
	  					<div class="del-text" @click="vFun_select_address(item)">
	  						<p>{{item.deliveryContact}}&nbsp;{{item.deliveryPhone}}</p>
	  						<p>{{item.deliveryAddress}}</p>
	  					</div>
	  					<div class="del-moren">
	  						<span class="moren-left">
                  <span v-if="item.deliveryDefault==1" :class="{defaultRed:item.deliveryDefault==1}">默认地址</span>
                  <span v-else @click="deliveryMakeDefault(item.deliveryCode)">设为默认</span>
	  						</span>
	  						<span class="moren-right">
	  							<a @click="vfun_update(index,MemberDeliverySet.list)"><em class="iconfont">&#xe6af;</em> 编辑</a>
	  							<a @click="deliveryDelete(index,MemberDeliverySet.list)"><em class="iconfont">&#xe653;</em> 删除</a>
	  						</span>
	  					</div>
	  				</li>
	  			</ul>
  			</Radio-group>
  		</div>
	    <div class="footer">
	    	<a @click="vfun_addDelivery"><em class="iconfont">&#xe685;</em>新增地址</a>
	    </div>
	</div>
  </div>
</template>

<script>
	import { MessageBox } from 'mint-ui';
  import { Toast } from 'mint-ui';  //引入弹框
export default {
  name: 'index',
  data () {
    return {
      jumpCondition:"", //地址跳转判断
    	vertical: '默认',
    	MemberDeliverySet:{
    		"list":[],
    	},
    	vue_moren:'设为默认',
    }
  },
  methods:{
  	vfun_update(index,obj){
  		localStorage.setItem("deliveryCode",obj[index].deliveryCode);
  		this.$router.push({path:"/updateDelivery"})
  	},
  	vfun_addDelivery(){
  		this.$router.push({path:"/addDelivery"})
  	},
	delivery(){
		this.axios({
				method: 'POST',
				url: "/v3/member/deliverys/listAll",
				data:{
//					"deliveryArea":'',
				}
				}).then((res) => {
					this.MemberDeliverySet.list=res.data.list;
				}).catch((err)=>{

	  	});
	},
	deliveryDelete(index,obj){
		MessageBox({
		  title: '提示',
		  message: '请确认是否删除？',
		  confirmButtonText:'确认',
		  cancelButtonText:'取消',
		  confirmButtonClass:'redBg',
		  showCancelButton: true
		}).then(btnType=>{
			if(btnType=='confirm'){
				this.axios({
					method: 'DELETE',
					url: "/v3/member/deliverys/"+obj[index].deliveryCode,
					data:{}
					}).then((res) => {
          Toast({
            message: '操作成功',
            iconClass: 'fontSize iconfont icon-chenggong'
          });
						this.delivery();
					}).catch((err)=>{
		  	});
			}
		})
	},
	//设为默认地址
	deliveryMakeDefault(deliveryCode) {
				this.axios({
					method: 'PATCH',
					url: "/v3/member/deliverys/"+deliveryCode+"/makeDefault",
					data:{},
					params:{
						"memberCode":''
					},
				}).then((res) => {
					this.Public.vFun_openSuccess("操作成功！");
					this.delivery();
				}).catch((err)=>{
					this.Public.vFun_openError(err.response.data)
				});
			},

  	vfun_back(){
  		history.back();
  	},

  	vFun_select_address(data){
  		localStorage.setItem('delivery',JSON.stringify(data));
  		if(!this.jumpCondition){
        this.$router.push({path:'/saveOrder'});
      }
  	}
  },
  activated(){
  	this.delivery();
  },
  mounted(){
  },
  activated(){
    this.jumpCondition = this.$route.query.value;
  	this.delivery();
  	document.querySelector('#vue_id_title').innerHTML="收货地址";
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
*{
	transition: 0.2s;
}
h1, h2 {
  font-weight: normal;
}

ul {
  list-style-type: none;
  padding: 0;
}
.index{
	box-sizing: border-box;
	background: #d2d3d9;
	margin-bottom: 1.5rem;
}

.delivery{
}
.delivery li{
	margin-bottom: 0.2rem;
	border-bottom: 1px solid #bbb;
	border-top: 1px solid #bbb;
	box-sizing: border-box;background: #fff;
}
.delivery li:first-child{
	border-top:0 ;
}
.delivery li div{
	padding:2.5% 5%;
	box-sizing: border-box;
}
.del-text{
	border-bottom: 1px solid #bbb;
}
.del-text p{
	line-height: 0.6rem;
}
.del-text p:first-child{
	font-weight: bold;
}
.del-moren{
	overflow: hidden;
}
.moren-left{
	float: left;
  display: block;
  height: 30px;
  line-height: 30px;
}
.moren-right{
	float: right;
	line-height: 30px;
}

.moren-right a{
   color: #565656!important;
}
.moren-right em{
	/*font-size: 15px;*/
	position: relative;
	top: 0.05rem;
	margin-left: 0.3rem;
	margin-right: 0.1rem;
}
.footer{
	position: fixed;
	background: #fff;
	bottom: 0;
	width: 100%;
}
.footer a{
	display: block;
	width: 98%;
	margin-left: 1%;
	margin-bottom: 1%;
	color: #fff;
	text-align: center;
	height: 1.4rem;
	font-size:14px;
	background: #D50B0A;
	line-height: 1.4rem;
}

  .defaultRed{
    color: #D50B0A ;
  }
</style>
